/**
 * 
 */
package releasemanager;

import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.io.File;

import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;


import org.w3c.dom.NodeList;

import updateManager.UpdateManager;

/**
 * @author tsku1386
 *
 */
public class ManageSVN {

	/**
	 * 
	 */
/*	
	private ISVNAuthenticationManager authManager;
    private SVNWCClient wcClient;
    UpdateManager um = new UpdateManager();
    private String user = um.USER;
	
	public ManageSVN() {
		
		File filecf;
	    filecf = new File(um.PRKPATH);
	    File confdir;
	    confdir = new File("C:/ReleaseManager/conf.cf");
	    String passphrase = null;
	    if(um.PASSPHRASE.equalsIgnoreCase("yes")){
	      final JPasswordField jpf = new JPasswordField();
	      JOptionPane jop = new JOptionPane(jpf,
	        JOptionPane.QUESTION_MESSAGE,
	        JOptionPane.OK_CANCEL_OPTION);
	      JDialog dialog = jop.createDialog(null,"Enter passphrase for svn:");
	      dialog.addComponentListener(new ComponentAdapter(){
	        public void componentShown(ComponentEvent e){
	          jpf.requestFocusInWindow();
	        }
	      });
	      dialog.setVisible(true);
	      int result = (Integer)jop.getValue();
	      dialog.dispose();
	      if(result == JOptionPane.OK_OPTION){
	        passphrase = String.valueOf(jpf.getPassword());
	      }
	    }

	    authManager = SVNWCUtil.createDefaultAuthenticationManager(confdir,user,null,filecf,passphrase,false);

	    wcClient =
	    SVNClientManager.newInstance(null,authManager).getWCClient();
		
	}
	
	public SVNStatusType getStatus(File file) throws Exception {
	    SVNStatusClient wcStatus = SVNClientManager.newInstance(null,authManager).getStatusClient();
	    return wcStatus.doStatus(file,false).getContentsStatus();
	}

	public String getSVNPath(File file) throws SVNException {
	    SVNInfo info = wcClient.doInfo(file,
	    SVNRevision.WORKING);
	    String repPath = info.getURL().toString().replaceFirst("/"+file.getName(),"").replaceAll("svn\\+ssh://"+user+"@svn.sk.firstdata.com/home/svn_tol","");
	    //svn+ssh://tsku1386@svn.sk.firstdata.com/home/svn_tol svn+ssh://"+user.trim()+
	    //addLog("getSVNPath ",repPath);
	    return repPath;
	}

	public SVNRevision getRevision(File file) throws SVNException {
	    SVNInfo info = wcClient.doInfo(file,
	    SVNRevision.WORKING);
	    return info.getCommittedRevision();
	}

	public boolean searchNodeChild(NodeList nl,String find){

	    boolean hasNode = false;

	    for(int i=0;i<nl.getLength();i++){
	      if(nl.item(i).getNodeName().equals(find))
	        hasNode = true;
	    }
	    return hasNode;
	}
	/*
	public boolean exists (String filename, String workdir) {

	      String dirUp = ".."+File.separator;
	      int i = 0;
	      while(!(new File (workdir+File.separator+dirUp+filename)).exists()){
	        dirUp = dirUp+dirUp;
	        i++;
	        if(i==3)
	         return false;
	      }
	      //System.out.println(dirUp+filename);
	      file = new File (workdir+File.separator+dirUp+filename);
	      return true;
	  }
	*/
}
